﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage/ContentManageMaster.Master"
    AutoEventWireup="true" CodeBehind="MenuList.aspx.cs" Inherits="Omes.Admin.ContentManage.MenuList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <ul id="contentul">
        <li><a id="addmenu" href="MenuAdd.aspx">添加栏目</a></li><li><a id="menulist" href="MenuList.aspx">栏目列表</a></li></ul>
    <table>
        <tr>
            <th>
                栏目名称
            </th>
            <th>
                页面类型
            </th>
            <th>
                父页面
            </th>
            <th>
                是否显示
            </th>
            <th>
                是否新窗口打开
            </th>
            <th>
                操作
            </th>
        </tr>
        <%foreach (Omes.Model.Page currentPage in CurrentPages)
          {%>
        <tr>
            <td>
                <%=currentPage.PageName %>
            </td>
            <td>
                <%=GetPageType(currentPage.PageTypeId).PageTypeName %>
            </td>
            <td>
                <%=GetPage(currentPage.ParentId).PageName %>
            </td>
            <td>
                <%=currentPage.ShowOnNar %>
            </td>
            <td>
                <%=currentPage.NewWindow %>
            </td>
            <td>
                <label id="editlabel<%=currentPage.Id %>" pid="<%=currentPage.Id %>" onclick="labelButtonShowOne(<%=currentPage.Id %>)"
                    style="background-color: Gray; width: 20px; height: 10px; border: 1px solid Balck;
                    margin-right: 2px; cursor: pointer;">
                    编辑</label>
                <label id="deletepageinfo<%=currentPage.Id %>" pid="<%=currentPage.Id %>" onclick="deletePage(<%=currentPage.Id %>)" style="background-color: Gray;
                    width: 20px; height: 10px; border: 1px solid Balck; cursor: pointer;">
                    删除</label>
                <label id="undolabel<%=currentPage.Id %>" pid="<%=currentPage.Id %>" onclick="labelButtonShowTwo(<%=currentPage.Id %>)"
                    style="background-color: Gray; width: 20px; height: 10px; border: 1px solid Balck;
                    cursor: pointer; display: none;">
                    取消</label>
                <label id="updatepageinfo<%=currentPage.Id %>" pid="<%=currentPage.Id %>" style="background-color: Gray;
                    width: 20px; height: 10px; border: 1px solid Balck; margin-right: 2px; cursor: pointer;
                    display: none;">
                    更新</label>
            </td>
        </tr>
        <%} %>
    </table>
    <div class="separatepagediv">
        <%for (int i = 1; i <= PagesCount; i++)
          {%>
        <a href="MenuList.aspx?numPage=<%=i %>">
            <%=i %></a>
        <%}%>
    </div>
    <script type="text/javascript" src="/Scripts/myjs.js"></script>
    <script type="text/javascript">
        function labelButtonShowOne(id) {
            //            $("#updatepageinfo" + id).show();
            //            $("#undolabel" + id).show();
            //            $("#editlabel" + id).hide();
            //            $("#deletepageinfo" + id).hide();
            //            var tds = $("#updatepageinfo" + id).parentsUntil("table", "tr").children();

            $("#jumpdiv").show();
            showJumpDiv(id);
        }

        function showJumpDiv(id) {
            var tds = $("#updatepageinfo" + id).parentsUntil("table", "tr").children();
            $("#menuName").html(tds[0].innerText);
            var types = GetMenuTypes();
            for (i = 0; i < types.length; i++) {
                $("#menutype").append("<option value=" + types[i].Id + ">" + types[i].PageTypeName + "</option>");
            }
            $("#menutype").find("option:contains('" + tds[1].innerText + "')").attr("selected",true);
            var pages = GetMenuParentPages();
            for (i = 0; i < pages.length; i++) {
                $("#parentpage").append("<option value=" + pages[i].Id + ">" + pages[i].PageName + "</option>");
            }
            $("#parentpage").find("option:contains('" + tds[2].innerText + "')").attr("selected", true);
//            $("#updatemenubtn").unbind("onclick", id, updatePage(id));
//            $("#updatemenubtn").bind("onclick", id, updatePage(id));
            $("#updatemenubtn").click(function () {
                updatePage(id);
            });
        }

        function updatePage(id) {
            var pagetype = $("#menutype").val();
            var parentPage = $("#parentpage").val();
            var showflag = $("#showflag").val();
            var openway = $("#openway").val();
            $.ajax({
                type: "POST",
                url: "/jsserver/page/update",
                data: { id: id, type: pagetype, parent: parentPage, bar: showflag, window: openway },
                success: function (data) {
                    location = location;
                },
                error: function () {
                    alert('保存失败，请重新修改！');
                }
            });
        }

        function deletePage(id) {
            $.ajax({
                type: "GET",
                url: "/jsserver/page/delete",
                data: { id: id },
                success: function (data) {
                    location = location;
                }
            });
         }

        function labelButtonShowTwo(id) {
            //            $("#updatepageinfo" + id).hide();
            //            $("#undolabel" + id).hide();
            //            $("#editlabel" + id).show();
            //            $("#deletepageinfo" + id).show();
        }

        $().ready(function () {
            $("#jumpdiv").hide();

            $("#contentul a").click(function () {
                $("#contentul a").removeClass("mousein")
                $("#contentul a").removeClass("mouseinb");
                $("#" + $(this).attr("id")).addClass("mouseinb");
            });

            $(".separatepagediv a").click(function () {
                $(this).attr("style", "font-size:30px");
            });
        });

    </script>
    <div id="jumpdiv" class="jumpdiv-back">
        <div class="jumpdiv-forward">
            <table>
                <tr>
                    <td style="width: 20%; background-color: Yellow;">
                        栏目名称:
                    </td>
                    <td>
                        <label id="menuName">
                        </label>
                    </td>
                </tr>
                <tr>
                    <td style="width: 20%; background-color: Yellow;">
                        页面类型:
                    </td>
                    <td>
                        <select id="menutype">
                        </select>
                    </td>
                </tr>
                <tr>
                    <td style="width: 20%; background-color: Yellow;">
                        父页面:
                    </td>
                    <td>
                        <select id="parentpage">
                        </select>
                    </td>
                </tr>
                <tr>
                    <td style="width: 20%; background-color: Yellow;">
                        是否显示在导航:
                    </td>
                    <td>
                        <select id="showflag">
                            <option value="true">是</option>
                            <option value="false" selected="selected">否</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td style="width: 20%; background-color: Yellow;">
                        打开方式:
                    </td>
                    <td>
                        <select id="openway">
                            <option value="true">新窗口</option>
                            <option value="false" selected="selected">原窗口</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td style="width: 20%; background-color: Yellow;">
                        &nbsp;
                    </td>
                    <td>
                        <input type="button" style="width: 15%" id="updatemenubtn" value="更新" />
                        <input type="button" style="width: 15%" onclick="$('#jumpdiv').hide();" id="cancelupdatemenubtn"
                            value="取消更新" />
                    </td>
                </tr>
            </table>
        </div>
    </div>
</asp:Content>
